package com.hyts.serialize.factory;

import com.esotericsoftware.kryo.Kryo;
import com.hyts.serialize.base.BeanFactory;
import com.hyts.serialize.bean.KryoBean;
import lombok.Builder;
import org.objenesis.strategy.StdInstantiatorStrategy;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.serialize.factory
 * author:Libo/Alex
 * create-date:2019-06-21 20:25
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: kryo框架的构建服务对象工厂方法对象类
 */
@Builder
public class KryoBeanFactory implements BeanFactory<KryoBean, Kryo> {


    @Override
    public Kryo create(KryoBean param) {
        Kryo kryo = new Kryo();
        kryo.setClassLoader(KryoBeanFactory.class.getClassLoader());
        kryo.setCopyReferences(param.isCopyReference());
        kryo.setReferences(param.isReference());
        kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
        kryo.setRegistrationRequired(param.isRegisted());
        return kryo;
    }

    @Override
    public Kryo create() {
        return new Kryo();
    }
}
